{extend name='common/container'}
{block name="content"}
<div :style="!urlobj.dialogstate ? 'margin:0 15px 15px 15px;':''">
<el-card shadow="never" :style="!urlobj.dialogstate ? 'min-height:80vh':'margin:0;padding:0;min-height:100vh'">
<div v-if="search_visible" id="search" class="search" style="margin-bottom:10px;">
	<el-form ref="form" size="small" :model="searchData" inline>
		<el-form-item label="需求标题">
			<el-input id="require_title" v-model="searchData.require_title"  style="width:150px;" placeholder="请输入需求标题"></el-input>
		</el-form-item>
		<el-form-item label="学生姓名">
			<el-input id="children_name" v-model="searchData.children_name"  style="width:150px;" placeholder="请输入学生姓名"></el-input>
		</el-form-item>
		<el-form-item label="学生年级">
			<el-select   style="width:150px" v-model="searchData.require_grade" filterable clearable placeholder="请选择">
				<el-option v-for="(item,i) in require_grade" :key="i" :label="item.key" :value="item.val"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="辅导学科">
			<el-select   style="width:150px" v-model="searchData.require_subject" filterable clearable placeholder="请选择">
				<el-option v-for="(item,i) in require_subject" :key="i" :label="item.key" :value="item.val.toString()"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="需求状态">
			<el-select style="width:150px" v-model="searchData.require_status" filterable clearable placeholder="请选择">
				<el-option key="0" label="草稿" value="0"></el-option>
				<el-option key="1" label="已发布" value="1"></el-option>
				<el-option key="2" label="招募中" value="2"></el-option>
				<el-option key="3" label="已关闭" value="4"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="审核状态">
			<el-select style="width:150px" v-model="searchData.cert_status" filterable clearable placeholder="请选择">
				<el-option key="0" label="待审核" value="0"></el-option>
				<el-option key="1" label="审核成功" value="1"></el-option>
				<el-option key="2" label="审核失败" value="2"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="发布时间">
			<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" type="daterange" v-model="searchData.create_time" clearable range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
		</el-form-item>
		<search-tool :page_data.sync="page_data" :search_data.sync="searchData" :is_clear.sync="is_clear" @refesh_list="index"></search-tool>
	</el-form>
</div>
<div v-if="filterGroupButtons && filterGroupButtons.length > 0" class="btn-group" style="margin-bottom:10px;">
	<div>
		<el-button v-for="item in filterGroupButtons" :key="item.access" :disabled="$data[item.disabled]" :type="item.color" size="mini" :icon="item.icon" @click="fn(item.clickname,'')">
			<span v-if="item.batch" v-text="$data['batchUpdateStatus']?'批量保存':'批量编辑'"></span>
			<span v-else v-text="item.name"></span>
		</el-button>
	</div>
	<div><table-tool tableid="parent_requirement" :search_visible.sync="search_visible"   @refesh_list="index"></table-tool></div>
</div>
<el-table id="parent_requirement" :row-class-name="rowClass" @selection-change="selection"  @row-click="handleRowClick"  row-key="requirement_id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @sort-change='sortChange' v-loading="loading"  ref="multipleTable" border class="eltable" :data="list"  style="width: 100%">
	<el-table-column align="center" type="selection" width="42"></el-table-column>
	<el-table-column align="center" type = '' property="requirement_id"  label="编号"  width="70">
	</el-table-column>
	<el-table-column align="center"  property="require_title"  label="需求标题" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="children_name"  label="学生姓名" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="require_grade"  label="学生年级" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="require_subject"  label="辅导学科" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="current_learning"  label="当前学习水平" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="expect_learning"  label="期望达到目标" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="expect_start_time"  label="期望授课开始时间" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="expect_end_time"  label="期望授课结束时间" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="expect_frequency"  label="期望授课频次" show-overflow-tooltip width="">
		<template slot-scope="scope">
			<span v-if="scope.row.expect_frequency == '1'" >每周1次</span>
			<span v-if="scope.row.expect_frequency == '2'" >每周2次</span>
			<span v-if="scope.row.expect_frequency == '3'" >每周3次</span>
			<span v-if="scope.row.expect_frequency == '4'" >每天</span>
		</template>
	</el-table-column>
	<el-table-column align="center"  property="teach_hour"  label="授课时长" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="teach_address"  label="授课地点" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="teach_address_detail"  label="授课地点详情" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="teach_address_lng"  label="授课地点经度" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="teach_address_lat"  label="授课地点维度" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="require_teacher_sex"  label="老师性别要求" show-overflow-tooltip width="">
		<template slot-scope="scope">
			<span v-if="scope.row.require_teacher_sex == '0'" >无要求</span>
			<span v-if="scope.row.require_teacher_sex == '1'" >男</span>
			<span v-if="scope.row.require_teacher_sex == '2'" >女</span>
		</template>
	</el-table-column>
	<el-table-column align="center"  property="require_teacher_year"  label="教学经验要求" show-overflow-tooltip width="">
		<template slot-scope="scope">
			<span v-if="scope.row.require_teacher_year == '0'" >无要求</span>
			<span v-if="scope.row.require_teacher_year == '1'" >1年以上</span>
			<span v-if="scope.row.require_teacher_year == '2'" >3年以上</span>
			<span v-if="scope.row.require_teacher_year == '3'" >5年以上</span>
		</template>
	</el-table-column>
	<el-table-column align="center"  property="require_teacher_year_min"  label="年龄偏好最小" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="require_teacher_year_max"  label="年龄偏好最大" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="require_other"  label="其他要求" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="class_fee"  label="课时费" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="estimated_hour"  label="预估课时" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="link_name"  label="联系人" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="link_mobile"  label="联系人手机号" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="require_status"  label="需求状态" show-overflow-tooltip width="">
		<template slot-scope="scope">
			<el-tag type="primary" v-if="scope.row.require_status == '0'" size="mini" effect="dark">草稿</el-tag>
			<el-tag type="primary" v-if="scope.row.require_status == '1'" size="mini" effect="dark">已发布</el-tag>
			<el-tag type="success" v-if="scope.row.require_status == '2'" size="mini" effect="dark">招募中</el-tag>
			<el-tag type="danger" v-if="scope.row.require_status == '4'" size="mini" effect="dark">已关闭</el-tag>
		</template>
	</el-table-column>
	<el-table-column align="center"  property="cert_status"  label="审核状态" show-overflow-tooltip width="">
		<template slot-scope="scope">
			<el-tag type="primary" v-if="scope.row.cert_status == '0'" size="mini" effect="dark">待审核</el-tag>
			<el-tag type="success" v-if="scope.row.cert_status == '1'" size="mini" effect="dark">审核成功</el-tag>
			<el-tag type="danger" v-if="scope.row.cert_status == '2'" size="mini" effect="dark">审核失败</el-tag>
		</template>
	</el-table-column>
	<el-table-column align="center"  property="cert_time"  label="审核时间" show-overflow-tooltip width="">
		<template slot-scope="scope">
			{{parseTime(scope.row.cert_time)}}
		</template>
	</el-table-column>
	<el-table-column align="center"  property="parent.parent_name"  label="发布人" show-overflow-tooltip width="">
	</el-table-column>
	<el-table-column align="center"  property="create_time"  label="发布时间" show-overflow-tooltip width="">
		<template slot-scope="scope">
			{{parseTime(scope.row.create_time)}}
		</template>
	</el-table-column>
	<el-table-column align="center"  property="update_time"  label="更新时间" show-overflow-tooltip width="">
		<template slot-scope="scope">
			{{parseTime(scope.row.update_time)}}
		</template>
	</el-table-column>
	<el-table-column :fixed="ismobile()?false:'right'" label="操作" align="center" width="190">
		<template slot-scope="scope">
			<div v-if="scope.row.requirement_id">
				<el-button v-for="item in filterListButtons" :key="item.access" :type="item.color" size="mini" :icon="item.icon" @click="fn(item.clickname,scope.row)">
					{{item.name}}
				</el-button>
			</div>
		</template>
	</el-table-column>
</el-table>
<Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="index" />
</el-card>

<!--添加-->
<Add :show.sync="dialog.addDialogStatus" size="small" @refesh_list="index"></Add>
<!--修改-->
<Update :info="updateInfo" :show.sync="dialog.updateDialogStatus" size="small" @refesh_list="index"></Update>
<!--查看详情-->
<Detail :info="detailInfo" :show.sync="dialog.detailDialogStatus" size="small" @refesh_list="index"></Detail>

</div>

{/block}
{block name="script"}
<script src="__PUBLIC__/assets/js/app.js"></script>
<script src="__PUBLIC__/components/admin/parents/requirement/add.js?v=<?php echo rand(1000,9999)?>"></script>
<script src="__PUBLIC__/components/admin/parents/requirement/update.js?v=<?php echo rand(1000,9999)?>"></script>
<script src="__PUBLIC__/components/admin/parents/requirement/detail.js?v=<?php echo rand(1000,9999)?>"></script>
<script>
new Vue({
	el: '#app',
	components:{
	},
	data: function() {
		return {
			dialog: {
				addDialogStatus : false,
				updateDialogStatus : false,
				detailDialogStatus : false,
			},
			searchData:{},
			button_group:[
				{
					name:'添加',
					color:'success',
					access:'/admin/Parents.Requirement/add.html',
					icon:'el-icon-plus',
					disabled:'',
					clickname:'add',
					showGroup:true,
				},
				{
					name:'修改',
					color:'primary',
					access:'/admin/Parents.Requirement/update.html',
					icon:'el-icon-edit',
					disabled:'single',
					clickname:'update',
					showGroup:true,
					showList:1,
				},
				{
					name:'删除',
					color:'danger',
					access:'/admin/Parents.Requirement/delete.html',
					icon:'el-icon-delete',
					disabled:'multiple',
					clickname:'del',
					showGroup:true,
					showList:1,
				},
				{
					name:'查看详情',
					color:'info',
					access:'/admin/Parents.Requirement/detail.html',
					icon:'el-icon-view',
					disabled:'single',
					clickname:'detail',
					showGroup:true,
				},
			],
			loading: false,
			page_data: {
				limit: 20,
				page: 1,
				total:20,
			},
			order:'',
			sort:'',
			ids: [],
			single:true,
			multiple:true,
			search_visible:true,
			list: [],
			require_grade: [],
			require_subject: [],
			updateInfo:{},
			detailInfo:{},
			is_clear:false,
		}
	},
	computed: {
		filterGroupButtons() {
			return this.button_group.filter(item => item.showGroup && checkPermission(item.access,"{:implode(',',session('admin.access'))}","{:session('admin.role_id')}",[1]));
		},
		filterListButtons() {
			return this.button_group.filter(item => item.showList == 1 && checkPermission(item.access,"{:implode(',',session('admin.access'))}","{:session('admin.role_id')}",[1]));
		},
		filterOtherButtons() {
			return this.button_group.filter(item => item.showList == 2 && checkPermission(item.access,"{:implode(',',session('admin.access'))}","{:session('admin.role_id')}",[1]));
		},
	},
	methods:{
		index(){
			let param = {limit:this.page_data.limit,page:this.page_data.page,order:this.order,sort:this.sort}
			Object.assign(param, this.searchData,this.urlobj)
			this.loading = true
			axios.post(base_url + '/Parents.Requirement/index',param).then(res => {
				if(res.data.status == 200){
					this.list = res.data.data.data
					this.page_data.total = res.data.data.total
					this.loading = false
					if(this.page_data.page == 1){
						this.require_grade = res.data.sql_field_data.require_grades
						this.require_subject = res.data.sql_field_data.require_subjects
					}
				}else{
					this.$message.error(res.data.msg);
				}
			})
		},
		updateExt(row,field){
			if(row.requirement_id){
				axios.post(base_url + '/Parents.Requirement/updateExt',{requirement_id:row.requirement_id,[field]:row[field]}).then(res => {
					if(res.data.status == 200){
						this.$message({message: res.data.msg, type: 'success'})
					}else{
						this.$message.error(res.data.msg)
					}
				})
			}
		},
		add(){
			this.dialog.addDialogStatus = true
		},
		update(row){
			let id = row.requirement_id ? row.requirement_id : this.ids.join(',')
			axios.post(base_url + '/Parents.Requirement/getUpdateInfo',{requirement_id:id}).then(res => {
				if(res.data.status == 200){
					this.dialog.updateDialogStatus = true
					this.updateInfo = res.data.data
				}else{
					this.$message.error(res.data.msg)
				}
			})
		},
		del(row){
			this.$confirm('确定操作吗?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				let ids = row.requirement_id ? row.requirement_id : this.ids.join(',')
				axios.post(base_url + '/Parents.Requirement/delete',{requirement_id:ids}).then(res => {
					if(res.data.status == 200){
						this.$message({message: res.data.msg, type: 'success'})
						this.index()
					}else{
						this.$message.error(res.data.msg)
					}
				})
			}).catch(() => {})
		},
		detail(row){
			this.dialog.detailDialogStatus = true
			this.detailInfo = {requirement_id:row.requirement_id ? row.requirement_id : this.ids.join(',')}
		},
		selection(selection) {
			this.ids = selection.map(item => item.requirement_id)
			this.single = selection.length != 1
			this.multiple = !selection.length
		},
		handleRowClick(row, rowIndex,event){
			if(event.target.className !== 'el-input__inner'){
				this.$refs.multipleTable.toggleRowSelection(row)
			}
		},
		rowClass ({ row, rowIndex }) {
			for(let i=0;i<this.ids.length;i++) {
				if (row.requirement_id === this.ids[i]) {
					return 'rowLight'
				}
			}
		},
		sortChange(val){
			if(val.order == 'descending'){
				this.order= 'desc'
			}
			if(val.order == 'ascending'){
				this.order= 'asc'
			}
			this.sort = val.prop
			this.index()
		},
		fn(method,data){
			if(data){
				this[method](data)
			}else{
				this[method](this.ids)
			}
		},
	},
	mounted(){
		this.index()
	},
})
</script>
{/block}
